package com.hanthink.common.utils.mdeia;

import java.util.HashMap;
import java.util.Map;

/**
* <p>Title: VideoProperties</p>  
* <p>Description: video 视频参数</p>  
* @author vondser
* @date 2020年12月25日
 */
public class MediaOptions {
	
	/**
     * 临时文件默认输入盘符
     */
    public static final String TMP_MEDIA_DEFAULT_DISK = "C:";
	
	private String cmd = "ffmpeg -i ";

    private String src;

    private String dest;


    private final Map<String, Object> options = new HashMap<>();


    public String getCmd() {
        return cmd;
    }

    public MediaOptions setCmd(String cmd) {
        this.cmd = cmd;
        return this;
    }

    public String getSrc() {
        return TMP_MEDIA_DEFAULT_DISK + src;
    }

    public MediaOptions setSrc(String src) {
        this.src = src;
        return this;
    }

    public String getDest() {
        return TMP_MEDIA_DEFAULT_DISK + dest;
    }

    public MediaOptions setDest(String dest) {
        this.dest = dest;
        return this;
    }

    public Map<String, Object> getOptions() {
        return options;
    }


    public MediaOptions addOption(String conf, Object value) {
        options.put("-" + conf, value);
        return this;
    }



    public String build() {
        StringBuilder builder = new StringBuilder(this.cmd);
        builder.append(" ").append(this.src);

        for (Map.Entry<String, Object> entry : options.entrySet()) {
            builder.append(entry.getKey().startsWith("-") ? " " : " -")
                    .append(entry.getKey())
                    .append(" ").append(entry.getValue());
        }

        builder.append(" ").append(this.dest);
        return builder.toString();
    }

}
